/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.dao;

import br.com.deployment.daogenerico.DaoGenerico;
import br.com.deployment.entidade.registroimovel.Operacao;
import br.com.deployment.interfaces.OperacaoDaoIn;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author luciano
 */
@Stateless
@LocalBean
public class OperacaoDao extends  DaoGenerico<Operacao> implements OperacaoDaoIn{

    public OperacaoDao() {
        super(Operacao.class);
    }
    
    public List<Operacao> findOperacao(Operacao operacao) {
        
        List<Operacao> lstOperacao = new ArrayList<Operacao>();
        String sql = "Select o from Operacao o";
        
        if(operacao.getTipo() != null  && ! operacao.getTipo().equals("")){
            sql += " where lower(o.tipo) like lower(:tipo) ";
        }        
        Query q = getEm().createQuery(sql);
        if(operacao.getTipo() != null && ! operacao.getTipo().equals("")){
            q.setParameter("tipo", "%"+operacao.getTipo()+"%");
        }
        
        lstOperacao = q.getResultList();
        return lstOperacao;
    }
    
}
